$.boundPhone = function(lHTTP,lPop,$scope){
    var countdownNum = 60;//倒数秒数
    var t = undefined;//定义刷新倒数时间
    var boundPhonelinkStatic = "3";




        $.isBoundReHref = function(isBound,linkStatic){
            //alert(isBound)
            if (isBound != 1) {
                    lHTTP.jsonp("/UserGet?static=1")
                        .success(function(json,status){
                            //alert(access_token)
                                if(json.user.mobile != "" && json.user.mobile != null){
                                    if(linkStatic == "3"){
                                        location.href="#/pickUp";
                                    }
                                    else if(linkStatic == "4"){
                                        location.href="http://downloads.imlaidian.com";
                                    }
                                }

                        });
            }
            else{
                boundPhonelinkStatic = linkStatic;
                if(linkStatic == "3"){
                    location.href="#/pickUp";
                }
                else if(linkStatic == "4"){
                    location.href="http://downloads.imlaidian.com";
                }
            };

            if(boundPhonelinkStatic == "4"){
                $('.bound-phone .explain').text("下载APP登录后赠送20小时免费时长（赠送的免费时长可抵扣产生的费用）")
                $('.bound-phone .page-title span').text("下载步骤")
                $('.bound-phone  .two-page img').attr('src','images/download-icon-1.png');
                $('.bound-phone  .two-page span').text("下载App");
            }
            if(boundPhonelinkStatic == "3"){
                $('.bound-phone .explain').text("为了保障账户安全，请先绑定手机。")
                $('.bound-phone .page-title span').text("提现步骤")
                $('.bound-phone  .two-page img').attr('src','images/pickup-icon-2.png');
                $('.bound-phone  .two-page span').text("输入提现金额");
            }
        }





    $.countdown = function(){
        $('.scan').removeAttr("disabled");
        $('.bound-phone .get-code-button').text(countdownNum)
        countdownNum = countdownNum-1;
        if(countdownNum == 0){
            clearInterval(t);
            $('.bound-phone .get-code-button').text("获取验证码");
            $('.bound-phone .get-code-button').removeAttr("disabled");
            countdownNum = 60;
        }
    }

    var lineToPickUp = function(){
        //$('.bound-phone #lineToPickUp').click(function(){
            if(boundPhonelinkStatic == "3"){
                location.href="#/pickUp";
            }
            else{
                location.href="http://downloads.imlaidian.com";
            }
        //});
    }




    $('.bound-phone .phone').blur(function(){
        if($('.bound-phone .phone').val().length == 11 && !isNaN($('.bound-phone .phone').val())) {
            $('.get-sound-code').css('color', '#00C4C3');
            $('.get-sound-code').click(function () {
                lHTTP.jsonp("/authCodeGet?mobile=" + $('.bound-phone .phone').val() + "&type=1")
                    .success(function (json, status) {
                        if (json.result == 1) {
                            //$.popUpMessage(1, "验证码获取成功", "", "请输入验证码", null, null,null, 0);
                            lPop.popSet(2, $scope, "验证码获取成功", undefined, "images/right-icon.png", undefined, undefined, "请输入验证码", undefined, 3000);
                            $.countdown();
                            t = window.setInterval("$.countdown()", 1000);
                            $('.bound-phone .get-code-button').attr("disabled", "true");
                        }
                        else {
                            //$.popUpMessage(4, json.msg, "", "取消", null, null,null, 0);
                            lPop.popSet(2, $scope, json.msg, undefined, "images/wrong-icon.png", undefined, undefined, "取消", undefined, 3000);
                        }
                    });
            })
        }
        else{
            $('.get-sound-code').css('color', '#000000');
            $('.bound-phone .phone').unbind();
        }
    })


    $('.bound-phone .get-code-button').click(function(){
        if($('.bound-phone .phone').val().length != 11 && isNaN($('.bound-phone .phone').val())){
            //$.popUpMessage(4, "电话号码错误", "", "请输入正确的电话号码", null, null,null, 0);
            lPop.popSet(2 , $scope ,"电话号码错误" ,undefined , "images/wrong-icon.png" , undefined,undefined , "请输入正确的电话号码" , undefined,3000);
            return false;
        }
        //$.getJSON(requestHost+"authCodeGet?callback=?&mobile="+$('.bound-phone .phone').val(),function(json){
        lHTTP.jsonp("/authCodeGet?mobile="+$('.bound-phone .phone').val())
                .success(function(json,status){
            if(json.result == 1){
                //$.popUpMessage(1, "验证码获取成功", "", "请输入验证码", null, null,null, 0);
                lPop.popSet(2 , $scope ,"验证码获取成功" ,undefined , "images/right-icon.png" , undefined,undefined , "请输入验证码" , undefined,3000);
                $.countdown();
                t = window.setInterval("$.countdown()",1000);
                $('.bound-phone .get-code-button').attr("disabled","true");
            }
            else{
                //$.popUpMessage(4, json.msg, "", "取消", null, null,null, 0);
                lPop.popSet(2 , $scope ,json.msg ,undefined , "images/wrong-icon.png" , undefined,undefined , "取消" , undefined,3000);
            }
        });
    })

    $('.bound-phone .auth-phone').click(function(){
        //$.lineToPickUp();
        if($('.bound-phone .auth-code').val().length != 6){
            //$.popUpMessage(4, "验证码错误错误", "", "请输入正确的验证码", null, null,null, 0);
            lPop.popSet(2 , $scope ,"验证码错误" ,undefined , "images/wrong-icon.png" , undefined,undefined , "请输入正确的验证码" , undefined,3000);
            return false;
        }
        //$.getJSON(requestHost+"authCodeBoundPhoneForWeiXin?callback=?&access_token="+access_token+"&mobile="+$('.bound-phone .phone').val()+'&authCode='+$('.bound-phone .auth-code').val(),function(json) {
            lHTTP.jsonp("/authCodeBoundPhoneForWeiXin?mobile="+$('.bound-phone .phone').val()+'&authCode='+$('.bound-phone .auth-code').val())
                .success(function(json,status){
            if (json.result == 1) {
                //$.popUpMessage(1, "验证成功", "", "确定", "lineToPickUp", null,null, 1);
                lPop.popSet(2 , $scope ,"验证成功" ,undefined , "images/right-icon.png" , undefined,undefined , "确定" , lineToPickUp,undefined);
                access_token = json.access_token;
                setCookie("access_token",access_token);
                //$.lineToPickUp();
            }
            else{
                //$.popUpMessage(4, json.msg, "", "确定", null, null,null, 1);
                lPop.popSet(2 , $scope ,json.msg,undefined , "images/wrong-icon.png" , undefined,undefined , "确定" , undefined,3000);
            }
        })
    });
}
